﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using Microsoft.Win32.SafeHandles;

namespace JasLib.Interop.Win32
{
    public static partial class IPHLPAPI
    {
        [DllImport(Constants.ModuleNames.IPHLPAPI, EntryPoint = "GetIpErrorString", ExactSpelling = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        public static extern uint GetIpErrorString(
            [In] IP_STATUS ErrorCode,
            [Out] StringBuilder Buffer,
            [In, Out] ref uint Size);

        [DllImport(Constants.ModuleNames.IPHLPAPI, EntryPoint = "IcmpCloseHandle", ExactSpelling = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool IcmpCloseHandle([In] HANDLE IcmpHandle);

        [DllImport(Constants.ModuleNames.IPHLPAPI, EntryPoint = "IcmpCreateFile", ExactSpelling = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        public static extern HANDLE IcmpCreateFile();

        [DllImport(Constants.ModuleNames.IPHLPAPI, EntryPoint = "IcmpSendEcho", ExactSpelling = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        public static extern uint IcmpSendEcho(
            [In] HANDLE IcmpHandle,
            [In] IN_ADDR DestinationAddress,
            [In] UINT_PTR RequestData,
            [In] ushort RequestSize,
            [In] ref IP_OPTION_INFORMATION RequestOptions,
            [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 6)] byte[] ReplyBuffer,
            [In] uint ReplySize,
            [In] uint Timeout);
    }
}
